package com.it.service.impl;


import com.it.Bean.Guestbook;
import com.it.service.GuestbookService;
import com.it.dao.GuestbookDao;
import com.it.dao.impl.GuestbookDaoImpl;

import java.sql.SQLException;
import java.util.List;

public class GuestbookServiceImpl implements GuestbookService {
    @Override
    public Integer AddMessage(Guestbook gb) {
        //创建dao层的对象
        GuestbookDao guestbookDao = new GuestbookDaoImpl();
        int successflag=0;
        try {
            successflag=guestbookDao.insert(gb);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return successflag;
    }

    @Override
    public Integer DeleteMessage(int id) {
        //创建dao层的对象
        GuestbookDao guestbookDao = new GuestbookDaoImpl();
        int successflag=0;
        try {
            successflag = guestbookDao.delete(id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return successflag;
    }

    @Override
    public List<Object> queryInfo() {
        //创建dao层的对象
        GuestbookDao guestbookDao = new GuestbookDaoImpl();
        //调用AdminDaoImpl对象中的 public void setConnection(Connection connection)方法连接数据库
        List<Object> list = null;
        try {
            list = guestbookDao.getQueryAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
